/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vek.controllers.SearchAndList;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import vek.GUI.SearchAndListView.KeyboardView;
import vek.ObjectDatabase.Search;

/**
 * Controller for the part of the KeyboardPanel which has the done button and the backspace button.
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class KeyboardMainController implements ActionListener{
    
    private KeyboardView keyboardView;
    private NavigationPanelController navigationPanelController;

    /**
     * 
     * @param npc the NavigationPanelController which handles user input for this object.
     */
    
    public KeyboardMainController(NavigationPanelController npc)
    {
        navigationPanelController = npc;
    }
    
    /**
     * Sets the KeyboardView for this controller
     * @param kv the KeyboardView for this controler
     */
    
    public void setKeyboardView(KeyboardView kv)
    {
        keyboardView = kv;
    }
    
    /**
     * Method which is run when the user clicks on the done or backspace button.
     * 
     * @param e the ActionEvent which is created when the user clicks.
     */

    public void actionPerformed(ActionEvent e) {
        JButton button = (JButton) e.getSource();
        
        if(button.getName().equalsIgnoreCase("doneButton"))
        {
            keyboardView.addSavedTextField();
            keyboardView.hideKeyBoard();
            navigationPanelController.showNavigationPanel();
        }
        else if(button.getName().equalsIgnoreCase("backspacebutton"))
        {
            if(keyboardView.getTextFieldLength() > 0)
            {
                keyboardView.removeLastCharFromTextField();
                Search search = navigationPanelController.getCurrentSearch();
                search.removeLastSearchOfType(keyboardView.getCurrentSearchType());
                navigationPanelController.showInRightPanelFromSearch(search);
            }
        }
    }

}
